package com.xinxing.city.recovery.utils;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class LogWriter {
    public static void writeLog(Context context, String tag, String message) {
        // 外部存储的路径
        File externalStorageDir = context.getExternalFilesDir(null);
        File logFile = new File(externalStorageDir, "app_log.txt");
        Log.e("TT",logFile.getPath());
        try {
            // 打开文件输出流
            FileOutputStream fos = new FileOutputStream(logFile, true);
            PrintStream printStream = new PrintStream(fos);

            // 写入日志
            printStream.println("Tag: " + tag + ", Message: " + message);

            // 刷新并关闭流
            printStream.flush();
            printStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
